/*
 * json.l
 * This file is part of gURL
 *
 * Copyright (C) 2014 - Aleksey Konovalov
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Library General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

%{
#include <gtk/gtk.h>
#include "lex_common.h"

#define NUMBER_ATTRS "json_number", "foreground", "#008c00", "font", "monospace", NULL
#define STRING_ATTRS "json_string", "foreground", "#1060b6", "font", "monospace", NULL
#define PUNCTUATION_ATTRS "json_punctuation", "foreground", "#A06080", "font", "monospace", NULL
#define RESERVED_WORD_ATTRS "json_reserved_word", "foreground", "#0f4d75", "style", PANGO_STYLE_ITALIC, "font", "monospace", NULL

%}

%option prefix="json"
%option outfile="lex.yy.c"
%option noyywrap
%option reentrant
%option extra-type="struct ParseData*"

hexdigit [a-fA-F0-9]
char	[^"\\]|\\\"|\\\\|\\\/|\\b|\\f|\\n|\\r|\\t|\\u{hexdigit}{4}
chars	{char}+

int	-?[0-9]+
frac	\.[0-9]+
e	e|e\+|e-|E|E\+|E-
exp	{e}[0-9]+

string	\"{chars}*?\"
number	{int}({frac}|{exp}|{frac}{exp})?
objectstart	\{
objectend	\}
arraystart	\[
arrayend	\]
reservedword	true|false|null
space		[ \t\n\r]

%%
{string}        MARK_TEXT(STRING_ATTRS);
{number}        MARK_TEXT(NUMBER_ATTRS);
{arraystart}	MARK_TEXT(PUNCTUATION_ATTRS); INC_INDENT(); MARK_EOL();
{arrayend}      RESET_INDENT(), DEC_INDENT(); MARK_EOL(); MARK_TEXT(PUNCTUATION_ATTRS); MARK_EOL();
{objectstart}   MARK_TEXT(PUNCTUATION_ATTRS); INC_INDENT(); MARK_EOL();
{objectend}     RESET_INDENT(), DEC_INDENT(); MARK_EOL(); MARK_TEXT(PUNCTUATION_ATTRS); MARK_EOL();
{reservedword}  MARK_TEXT(RESERVED_WORD_ATTRS);
{space}	        IGNORE_TEXT();
:               MARK_TEXT(PUNCTUATION_ATTRS);
,               RESET_INDENT(), MARK_TEXT(PUNCTUATION_ATTRS); MARK_EOL();
%%

void highlight_json(GtkTextBuffer* tb, const gchar* text, size_t len,
                    gboolean prettyprint) {
	DO_HIGHLIGHT(json, tb, text, len, prettyprint);
}

